package com.call.project.frame;

import org.springframework.core.io.ClassPathResource;

import java.awt.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 Created by IntelliJ IDEA.
 User: wk
 Date: 2017-03-20 下午12:07
 */
public class MyTrayIcon extends TrayIcon {
    static final Toolkit tk   = Toolkit.getDefaultToolkit();
    static Image         img  = null;
    static {
        InputStream in = null;
        FileOutputStream out = null;
        File dll = null;
        try {
            in = new ClassPathResource("images/title_1.png").getInputStream();
            dll = File.createTempFile("title", ".png");
            out = new FileOutputStream(dll);
            int i;
            byte[] buf = new byte[1024];
            while ((i = in.read(buf)) != -1) {
                out.write(buf, 0, i);
            }
            out.flush();
            dll.deleteOnExit();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (in != null)
                try {
                    in.close();
                } catch (IOException e) {

                }
            if (out != null)
                try {
                    out.close();
                } catch (Exception e) {
                }
        }
        if (dll != null)
            img = tk.createImage(dll.toString());

    }

    public MyTrayIcon() {
        super(img);
        // 设置标题图标
    }

    public MyTrayIcon(Image image) {
        super(image);
    }

    public MyTrayIcon(Image image, String tooltip) {
        super(image, tooltip);
    }

    public MyTrayIcon(Image image, String tooltip, PopupMenu popup) {
        super(image, tooltip, popup);
    }
}
